package de.backtomedieval.game;

import de.backtomedieval.R;
import de.backtomedieval.main.Game;

public class Costs {
	
	/*
	 Wares:
	    0: food
	    1: gold
	    2: lumber
	    3: stone
	    4: iron
	*/
	
	private int[] multWares = {0,0,0,0,0};
	private int[] multSupply = {0,0,0,0,0};
	private String[] waresNames = Game.getStringArray(R.array.wares);
	
	public Costs(){}
	
	public int getWare(int level, int index) {
		return multWares[index] * level;
		//double ln = Math.log(level);
		//return (int) (multWares[index] * (ln*ln+1));
	}
	public int getSupply(int level, int index) {
		//return multSupply[index] * level;
		double ln = Math.log(level);
		return (int) (multSupply[index] * (ln*ln+1));
	}
	public void setCost(int ware, int mult) {
		multWares[ware] = mult;
	}
	public void setSupply(int supply, int mult) {
		multSupply[supply] = mult;
	}
	public int getFood(int level) {
		return getWare(level,0);
	}
	public int getGold(int level) {
		return getWare(level,1);
	}
	public int getLumber(int level) {
		return getWare(level,2);
	}
	public int getStone(int level) {
		return getWare(level,3);
	}
	public int getIron(int level) {
		return getWare(level,4);
	}
	public void setFoodCost(int mult) {
		setCost(0, mult);
	}
	public void setGoldCost(int mult) {
		setCost(1, mult);
	}
	public void setLumberCost(int mult) {
		setCost(2, mult);
	}
	public void setStoneCost(int mult) {
		setCost(3, mult);
	}
	public void setIronCost(int mult) {
		setCost(4, mult);
	}
	public void setFoodSupply(int mult) {
		setSupply(0,mult);
	}
	public void setGoldSupply(int mult) {
		setSupply(1,mult);
	}
	public void setLumberSupply(int mult) {
		setSupply(2,mult);
	}
	public void setStoneSupply(int mult) {
		setSupply(3,mult);
	}
	public void setIronSupply(int mult) {
		setSupply(4,mult);
	}
	public int getFoodSupply(int level) {
		return getSupply(level,0);
	}
	public int getGoldSupply(int level) {
		return getSupply(level,1);
	}
	public int getLumberSupply(int level) {
		return getSupply(level,2);
	}
	public int getStoneSupply(int level) {
		return getSupply(level,3);
	}
	public int getIronSupply(int level) {
		return getSupply(level,4);
	}
	
	
	
	public String toStringOld(int level) {
		String costs ="";
		String supply ="";
		for (int i=0; i<multWares.length; i++){
			if (getWare(level,i)!=0) {
				costs += getWare(level,i)+" " + waresNames[i] +" ";
			}
			if (getSupply(level,i)!=0) {
				supply += getSupply(level,i)+" "+ waresNames[i]+" ";
			}
		}
		if (!costs.equals("")) {
			costs = Game.getString(R.string.costs) + ": " + costs;
		}
		if (!supply.equals("")) {
			supply = Game.getString(R.string.supply) + ": " + supply +" (" +  Game.getString(R.string.perround)+ ")";
			return costs.trim() + "\n" + supply.trim();
		} else {
			return costs.trim();
		}
	}
	
	
	public String toString(int level) {
		String costs ="";
		String supply ="";
		for (int i=0; i<multWares.length; i++){
			if (getWare(level,i)!=0) {
				costs += "<img src=\"wares"+i+"\">" +" " + getWare(level,i) +" ";
			}
			if (getSupply(level,i)!=0) {
				supply += "<img src=\"wares"+i+"\">" +" " + getSupply(level,i)+" ";
			}
		}
		if (!costs.equals("")) {
			costs = Game.getString(R.string.costs) + ": " + costs;
		}
		if (!supply.equals("")) {
			supply = Game.getString(R.string.supply) +": " + supply ;
			return costs.trim() + "<br>" + supply.trim();
		} else {
			return costs.trim();
		}
	}
	
	public String getSupplyStringOld(int level) {
		String supply ="";
		for (int i=0; i<multWares.length; i++){
			if (getSupply(level,i)!=0) {
				supply += getSupply(level,i)+" "+ waresNames[i]+" ";
			}
		}
		if (!supply.equals("")) {
			supply = Game.getString(R.string.supply) + ":<br>" + supply + " (" +  Game.getString(R.string.perround)+ ")";
			return supply.trim() + "\n";
		} else {
			return "\n";
		}
	}
	
	
	public String getSupplyString(int level) {
		String supply ="";
		for (int i=0; i<multWares.length; i++){
			if (getSupply(level,i)!=0) {
				supply += "<img src=\"wares"+i+"\">"+ " " + getSupply(level,i)+" ";
			}
		}
		if (!supply.equals("")) {
			supply = Game.getString(R.string.supply)+  ": " + supply;
			return supply.trim();
		} else {
			return "";
		}
	}
}
